-- *************************************************************************
-- * TitanGoodbye.lua for Version 3.0 r1
-- * by Joejanko (MNyteTemplar @ Undermine)
-- *************************************************************************
-- * This plugin adds a right-side icon to Titan Panel that allows you to
-- * Logout, Exit Game, or Exit Now with a single click.  Displays in a
-- * tooltip the keystroke combinations for each option.
-- *
-- * Acknowledgements: This  was inspired by Lombra's Titan Panel [Logout].
-- *************************************************************************

-- ******************************* Constants *******************************
TITAN_GOODBYE_ID = "Goodbye";
TITAN_GOODBYE_VERSION = "3.0 r1";
TITAN_GOODBYE_TOOLTIP_HINTTEXT  = "Shift-left-click to Logout.\n"..TitanUtils_GetGreenText("Control-left-click to Exit Game.\n")..TitanUtils_GetGreenText("Alt-left-click to Exit Now.\n")..TitanUtils_GetGreenText("Left-click-drag to move the plugin.");

-- *************************************************************************

-- ******************************* Functions *******************************

-- *************************************************************************
-- NAME : TitanPanelGoodbyeButton_OnLoad()
-- DESC : Registers the plugin upon it loading. 
--        Also, an entry is made to the chat log when entering world.
--        Finally, the plugin is added to a table of right-side plugins.
--        This allows you to swap its position on the Titan bar only with
--        plugins in the table (right-side plugins).
-- *************************************************************************

function TitanPanelGoodbyeButton_OnLoad(self)
	    if( DEFAULT_CHAT_FRAME ) then
			DEFAULT_CHAT_FRAME:AddMessage(GREEN_FONT_COLOR_CODE.. "Titan Panel [Goodbye] v3.0 r1 by Joejanko (MNyteTemplar on Undermine)");
	end
	self.registry = {
		id = TITAN_GOODBYE_ID,
		version = TITAN_GOODBYE_VERSION,
		menuText = "Goodbye", 
		category = "Interface",
		tooltipTitle = "Goodbye Info", 
		tooltipTextFunction = "TitanPanelGoodbyeButton_GetTooltipText",
		icon =  "Interface\\GossipFrame\\TaxiGossipIcon.blp",
       	iconWidth = 16,
    };
	
	tinsert(TITAN_PANEL_NONMOVABLE_PLUGINS, TITAN_GOODBYE_ID)
end

-- *************************************************************************
-- Name: TitanPanelGoodbyeButton_GetTooltipText()
-- Desc: Gets the tooltip text, what appears when you hover over the icon
--       on the Titan Panel.  In this case, it displays the keystroke 
--       combinations for each action. *************************************************************************

function TitanPanelGoodbyeButton_GetTooltipText()
	return ""..
		TitanUtils_GetGreenText(TITAN_GOODBYE_TOOLTIP_HINTTEXT);
end

-- *************************************************************************
-- Name: TitanPanelGoodbyeButton_OnClick()
-- Desc: Determines what happens when you click the Goodbye icon. 
--       In this case, it sets a shift-left-click to Logout, a control-left-
--       click to Exit Game, and an alt-left-click to Exit Now. It sets a
--       right-click to hide the tooltip and display the right-click menu.
-- *************************************************************************

function TitanPanelGoodbyeButton_OnClick(self,button)
	if (button == "LeftButton" and IsShiftKeyDown()) then
		Logout();
	elseif (button == "LeftButton" and IsControlKeyDown()) then
		Quit();
	elseif (button == "LeftButton" and IsAltKeyDown()) then
		ForceQuit();
	elseif (button == "RightButton") then
		GameTooltip:Hide();
		TitanPanelRightClickMenu_Toggle(self);
	end
end

-- *************************************************************************
-- Name: TitanPanelRightClickMenu_PrepareGoodbyeMenu()
-- Desc: Adds the title and the Hide command to the right-click menu.
-- *************************************************************************

function TitanPanelRightClickMenu_PrepareGoodbyeMenu()
	TitanPanelRightClickMenu_AddTitle(TitanPlugins[TITAN_GOODBYE_ID].menuText);
	TitanPanelRightClickMenu_AddCommand(TITAN_PANEL_MENU_HIDE, TITAN_GOODBYE_ID, TITAN_PANEL_MENU_FUNC_HIDE);
end